package ai.leinao.notify.core.configuration;

import ai.leinao.notify.core.ResourceNotifierRegistry;
import ai.leinao.notify.core.ResourceTemplateRegistry;
import ai.leinao.notify.core.NotifierRegistry;
import ai.leinao.notify.core.template.TemplateRegistry;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.util.List;

/**
 * 消息通知配置
 *
 * @author zhong.wang
 * @date 2025/7/8
 */
@Configuration
@EnableConfigurationProperties({ResourceNotifyProperties.class})
public class NotifyAutoConfiguration {

    @Bean
    @Primary
    public TemplateRegistry templateRegistry(List<TemplateRegistry> templateRegistries) {
        return new CompositeTemplateRegistry(templateRegistries);
    }

    @Bean
    @Primary
    public NotifierRegistry notifierRegistry(List<NotifierRegistry> notifierRegistries) {
        return new CompositeNotifierRegistry(notifierRegistries);
    }


    @Bean
    public ResourceNotifierRegistry resourceNotifierRegistry(ResourceNotifyProperties resourceNotifyProperties, ApplicationContext applicationContext){
        return new ResourceNotifierRegistry(resourceNotifyProperties,applicationContext);
    }

    @Bean
    public ResourceTemplateRegistry resourceTemplateRegistry(ResourceNotifyProperties resourceNotifyProperties, ApplicationContext applicationContext){
        return new ResourceTemplateRegistry(resourceNotifyProperties,applicationContext);
    }

}
